package cn.mumzone.pos.presenter;

import cn.mumzone.basic.mvp.AbsPresenter;
import cn.mumzone.basic.net.http.callback.ApiCallBack;
import cn.mumzone.basic.net.response.BaseResponse;
import cn.mumzone.pos.AppConstants;
import cn.mumzone.pos.model.ReserveOrderEntity;
import cn.mumzone.pos.model.source.ReserveRepository;
import cn.mumzone.pos.presenter.contract.ReserveDetailContract;
import cn.mumzone.pos.util.AppUtil;

/**
 * Created by qiuzhenhuan on 2019/7/1.
 */

public class ReserveDetailPresenter extends AbsPresenter<ReserveDetailContract.View, ReserveRepository>
        implements ReserveDetailContract.Presenter {

    @Override
    public void doCancelHold(String appointmentId, String subAppointmentId) {
        ApiCallBack<String> callBack = new ApiCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                mView.showCancelHoldSuccess();
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.endOccupy(appointmentId, subAppointmentId, callBack);
        addSubscrebe(callBack);
    }

    @Override
    public void doCancelAllHold(String appointmentId) {
        ApiCallBack<String> callBack = new ApiCallBack<String>() {
            @Override
            public void onSuccess(String s) {
                mView.showCancelAllHoldSuccess();
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
//        mRepo.deleteServe(appointmentId, callBack);
        mRepo.endAllOccupy(appointmentId, callBack);
        addSubscrebe(callBack);
    }

    @Override
    public void loadReserveDetail(String reserveId) {
        ApiCallBack<ReserveOrderEntity> callBack = new ApiCallBack<ReserveOrderEntity>() {
            @Override
            public void onSuccess(ReserveOrderEntity reserveOrderEntity) {
                mView.showReserveDetail(reserveOrderEntity);
            }

            @Override
            public void onError(BaseResponse response) {
                mView.showError(response.getMsg());
            }
        };
        mRepo.selectOrderAppointmentDetail(reserveId, AppUtil.hasServiceBusiness() ? "1" : "2", callBack);
        addSubscrebe(callBack);
    }
}
